package org.softmed.rest.admin.config;

import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import main.RESTEditor;

import org.softmed.rest.admin.ModuleManager;
import org.softmed.rest.admin.DetailChooser.DetailLevel;
import org.softmed.rest.admin.file.CustomFileNode;
import org.softmed.rest.admin.file.DirectoryNode;
import org.softmed.rest.admin.module.ValidationException;

import restlet.description.convert.RESTConfigurationDescription;


public class ConfigurationEditor extends JPanel {

	RESTConfigurationDescription configurationDescription;

	ConfigurationPathHandler path = new ConfigurationPathHandler();
	ConfigurationActionPanel actionPanel;
	ModuleManager moduleManager;

	public ConfigurationEditor(RESTEditor editor) {
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

		actionPanel = new ConfigurationActionPanel(path, editor);
		// setBackground(Color.RED);

		setMinimumSize(new Dimension(100, 25));

		// resourceHeader.setRemoveListener(this);
		// actionPanel.setFileHandler(this);
		// actionPanel.setDetailListener(this);

		// resourceHandlerChooser.setVisible(false);
		// restMethodsManager.setVisible(true);

		add(path);
		add(actionPanel);
		add(moduleManager);

		moduleManager = new ModuleManager();
		configurationDescription = new RESTConfigurationDescription();
		moduleManager.setModuleDescriptions(configurationDescription
				.getModuleDescriptions());
		moduleManager.setActionPanel(actionPanel);
		actionPanel.setDetailListener(moduleManager);
		moduleManager.setFileHandler(editor);
		actionPanel.setFileHandler(editor);

		// detailLevelChanged(DetailLevel.HANDLER);
		// moduleManager.setDetailLevel(DetailLevel.HANDLER);
		// actionPanel.setDetailLevel(DetailLevel.HANDLER);
	}

	public void addNewModule() {
		moduleManager.addNewModule();
	}

	public RESTConfigurationDescription getConfigurationDescription() {
		return configurationDescription;
	}

	public void setConfigurationDescription(
			RESTConfigurationDescription configurationDescription) {
		this.configurationDescription = configurationDescription;
		moduleManager.setModuleDescriptions(configurationDescription
				.getModuleDescriptions());
	}

	public void validateData() throws ValidationException {
		moduleManager.validateData();

	}

	public void selectionChanged(CustomFileNode node) {
	
//		moduleManager.selectionPathChanged(directory, name, node.getDirPath());
//		actionPanel.selectionPathChanged(directory, name, node
//				.getDirPath());
	}

}
